﻿using System.IO;
using UnityEngine;

namespace BlockOS.Client.Res
{
    public class AppFiles
    {
        private string path;
        public AppFiles()
        {
            path = Application.persistentDataPath;
        }

        public bool Exists(string fileName)
        {
            return File.Exists(Path.Combine(path, fileName));
        }

        public string ReadText(string fileName)
        {
            using var inputStream = File.OpenRead(Path.Combine(path, fileName));
            using var reader = new StreamReader(inputStream);
            return reader.ReadToEnd();
        }

        public void SaveText(string fileName, string text)
        {
            using var outputStream = File.Open(Path.Combine(path, fileName), FileMode.Create, FileAccess.Write);
            using var writer = new StreamWriter(outputStream);
            writer.Write(text);
            outputStream.Flush();
        }
    }
}
